package com.sgu6.sgu6_machine.db;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.sgu6.sgu6_machine.db.converter.PhotoBeanConverter;
import java.util.List;

import com.sgu6.sgu6_machine.dto.GoodsSimpleDto;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "GOODS_SIMPLE_DTO".
*/
public class GoodsSimpleDtoDao extends AbstractDao<GoodsSimpleDto, Void> {

    public static final String TABLENAME = "GOODS_SIMPLE_DTO";

    /**
     * Properties of entity GoodsSimpleDto.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property Id = new Property(0, String.class, "id", false, "ID");
        public final static Property Name = new Property(1, String.class, "name", false, "NAME");
        public final static Property Title = new Property(2, String.class, "title", false, "TITLE");
        public final static Property CategoryId = new Property(3, String.class, "categoryId", false, "CATEGORY_ID");
        public final static Property ShortContent = new Property(4, String.class, "shortContent", false, "SHORT_CONTENT");
        public final static Property Content = new Property(5, String.class, "content", false, "CONTENT");
        public final static Property Model = new Property(6, String.class, "model", false, "MODEL");
        public final static Property Price = new Property(7, float.class, "price", false, "PRICE");
        public final static Property Cmd = new Property(8, String.class, "cmd", false, "CMD");
        public final static Property MarketPrice = new Property(9, float.class, "marketPrice", false, "MARKET_PRICE");
        public final static Property VarietyName = new Property(10, String.class, "varietyName", false, "VARIETY_NAME");
        public final static Property Sort = new Property(11, int.class, "sort", false, "SORT");
        public final static Property Enable = new Property(12, boolean.class, "enable", false, "ENABLE");
        public final static Property Photo = new Property(13, String.class, "photo", false, "PHOTO");
        public final static Property BarnId = new Property(14, String.class, "barnId", false, "BARN_ID");
    };

    private final PhotoBeanConverter photoConverter = new PhotoBeanConverter();

    public GoodsSimpleDtoDao(DaoConfig config) {
        super(config);
    }
    
    public GoodsSimpleDtoDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"GOODS_SIMPLE_DTO\" (" + //
                "\"ID\" TEXT," + // 0: id
                "\"NAME\" TEXT," + // 1: name
                "\"TITLE\" TEXT," + // 2: title
                "\"CATEGORY_ID\" TEXT," + // 3: categoryId
                "\"SHORT_CONTENT\" TEXT," + // 4: shortContent
                "\"CONTENT\" TEXT," + // 5: content
                "\"MODEL\" TEXT," + // 6: model
                "\"PRICE\" REAL NOT NULL ," + // 7: price
                "\"CMD\" TEXT," + // 8: cmd
                "\"MARKET_PRICE\" REAL NOT NULL ," + // 9: marketPrice
                "\"VARIETY_NAME\" TEXT," + // 10: varietyName
                "\"SORT\" INTEGER NOT NULL ," + // 11: sort
                "\"ENABLE\" INTEGER NOT NULL ," + // 12: enable
                "\"PHOTO\" TEXT," + // 13: photo
                "\"BARN_ID\" TEXT);"); // 14: barnId
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"GOODS_SIMPLE_DTO\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, GoodsSimpleDto entity) {
        stmt.clearBindings();
 
        String id = entity.getId();
        if (id != null) {
            stmt.bindString(1, id);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(2, name);
        }
 
        String title = entity.getTitle();
        if (title != null) {
            stmt.bindString(3, title);
        }
 
        String categoryId = entity.getCategoryId();
        if (categoryId != null) {
            stmt.bindString(4, categoryId);
        }
 
        String shortContent = entity.getShortContent();
        if (shortContent != null) {
            stmt.bindString(5, shortContent);
        }
 
        String content = entity.getContent();
        if (content != null) {
            stmt.bindString(6, content);
        }
 
        String model = entity.getModel();
        if (model != null) {
            stmt.bindString(7, model);
        }
        stmt.bindDouble(8, entity.getPrice());
 
        String cmd = entity.getCmd();
        if (cmd != null) {
            stmt.bindString(9, cmd);
        }
        stmt.bindDouble(10, entity.getMarketPrice());
 
        String varietyName = entity.getVarietyName();
        if (varietyName != null) {
            stmt.bindString(11, varietyName);
        }
        stmt.bindLong(12, entity.getSort());
        stmt.bindLong(13, entity.getEnable() ? 1L: 0L);
 
        List photo = entity.getPhoto();
        if (photo != null) {
            stmt.bindString(14, photoConverter.convertToDatabaseValue(photo));
        }
 
        String barnId = entity.getBarnId();
        if (barnId != null) {
            stmt.bindString(15, barnId);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, GoodsSimpleDto entity) {
        stmt.clearBindings();
 
        String id = entity.getId();
        if (id != null) {
            stmt.bindString(1, id);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(2, name);
        }
 
        String title = entity.getTitle();
        if (title != null) {
            stmt.bindString(3, title);
        }
 
        String categoryId = entity.getCategoryId();
        if (categoryId != null) {
            stmt.bindString(4, categoryId);
        }
 
        String shortContent = entity.getShortContent();
        if (shortContent != null) {
            stmt.bindString(5, shortContent);
        }
 
        String content = entity.getContent();
        if (content != null) {
            stmt.bindString(6, content);
        }
 
        String model = entity.getModel();
        if (model != null) {
            stmt.bindString(7, model);
        }
        stmt.bindDouble(8, entity.getPrice());
 
        String cmd = entity.getCmd();
        if (cmd != null) {
            stmt.bindString(9, cmd);
        }
        stmt.bindDouble(10, entity.getMarketPrice());
 
        String varietyName = entity.getVarietyName();
        if (varietyName != null) {
            stmt.bindString(11, varietyName);
        }
        stmt.bindLong(12, entity.getSort());
        stmt.bindLong(13, entity.getEnable() ? 1L: 0L);
 
        List photo = entity.getPhoto();
        if (photo != null) {
            stmt.bindString(14, photoConverter.convertToDatabaseValue(photo));
        }
 
        String barnId = entity.getBarnId();
        if (barnId != null) {
            stmt.bindString(15, barnId);
        }
    }

    @Override
    public Void readKey(Cursor cursor, int offset) {
        return null;
    }    

    @Override
    public GoodsSimpleDto readEntity(Cursor cursor, int offset) {
        GoodsSimpleDto entity = new GoodsSimpleDto( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // title
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // categoryId
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // shortContent
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // content
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // model
            cursor.getFloat(offset + 7), // price
            cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // cmd
            cursor.getFloat(offset + 9), // marketPrice
            cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // varietyName
            cursor.getInt(offset + 11), // sort
            cursor.getShort(offset + 12) != 0, // enable
            cursor.isNull(offset + 13) ? null : photoConverter.convertToEntityProperty(cursor.getString(offset + 13)), // photo
            cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14) // barnId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, GoodsSimpleDto entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setTitle(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setCategoryId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setShortContent(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setContent(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setModel(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setPrice(cursor.getFloat(offset + 7));
        entity.setCmd(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
        entity.setMarketPrice(cursor.getFloat(offset + 9));
        entity.setVarietyName(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10));
        entity.setSort(cursor.getInt(offset + 11));
        entity.setEnable(cursor.getShort(offset + 12) != 0);
        entity.setPhoto(cursor.isNull(offset + 13) ? null : photoConverter.convertToEntityProperty(cursor.getString(offset + 13)));
        entity.setBarnId(cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14));
     }
    
    @Override
    protected final Void updateKeyAfterInsert(GoodsSimpleDto entity, long rowId) {
        // Unsupported or missing PK type
        return null;
    }
    
    @Override
    public Void getKey(GoodsSimpleDto entity) {
        return null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
